<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="凭证 /合同名称、编号"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="recordId" stripe remoteSort remoteFilter>
				<el-table-column type="index" label="#"  width="50"></el-table-column>
				<el-table-column label="付款凭证" prop="voucherNo" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="付款合同" prop="contractJson" width="200" :show-overflow-tooltip="true">
					<template #default="scope">
						<el-button type="text"  @click="showContract(scope.row, scope.$index)">{{JSON.parse(scope.row.contractJson).title}}</el-button>
					</template>
				</el-table-column>
				<el-table-column label="付款人" prop="userName" width="100" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="付款日期" prop="payableTime" width="100"></el-table-column>
				<el-table-column label="付款方式" prop="payeeTypeName" width="100"></el-table-column>
				<el-table-column label="付款种类" prop="payReceivedTypeName" width="100"></el-table-column>
				<el-table-column label="付款金额" prop="amount" width="150"></el-table-column>
				<el-table-column label="备注说明" prop="remark" width="300" :show-overflow-tooltip="true"></el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<ContractDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></ContractDetails>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import ContractDetails from "@/views/finance/contract/contractDetails.vue";

export default {
	name: 'Payment Manage',
	components: {
		ContractDetails,
		scSelectFilter,
	},
	data() {
		return {
			dialog: {
				detailsSave:false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "付款种类",
					key: "payReceivedType",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				}
			],
			apiObj: this.$API.finance.contract.getAllContractPayableRecordList,
			selection: [],
			search: {
				date:'',
				payReceivedType:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getPayReceivedType();
	},
	methods: {
		showContract(row, index) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().showDetail(JSON.parse(row.contractJson).contractId)
			})
		},
		async getPayReceivedType()
		{
			var res = await this.$API.system.sysDic.getSysDicByCode.get({code:'payReceivedType'});
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data){
			this.search.date = data.date;
			this.search.payReceivedType = data.payReceivedType;
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
